﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Infrastructure.UI.WPF;
using Finance.Core;

namespace Finance.WPF
{
    /// <summary>
    /// Interaction logic for winFinance.xaml
    /// </summary>
    public partial class winFinance : BaseForm
    {
        public winFinance()
        {
            InitializeComponent();
        }
        public override void InitData()
        {
            this.lstFinance.ItemsSource = FinanceItem.List;
        }

        private void btnUpdate_Click(object sender, RoutedEventArgs e)
        {
            FinanceItem.SaveAll();
        }

        private void btnInsert_Click(object sender, RoutedEventArgs e)
        {
            FinanceItem.SaveAll();
            this.btnInsert.Visibility = Visibility.Hidden;
            this.btnUpdate.Visibility = Visibility.Visible;
            this.btnAdd.IsEnabled = true;
        }

        private void btnAdd_Click(object sender, RoutedEventArgs e)
        {
            FinanceItem newItem = new FinanceItem()
                   {
                       ID = Guid.NewGuid().ToString(),
                       Date = System.DateTime.Now,
                       Amount = 0
                   };
            FinanceItem.List.Add(newItem);
            this.lstFinance.ItemsSource = FinanceItem.List;
            this.lstFinance.SelectedItem = newItem;
            this.btnAdd.IsEnabled = false;
            this.btnInsert.Visibility = Visibility.Visible;
            this.btnUpdate.Visibility = Visibility.Hidden;
        }

    }
}
